<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="事件ID" prop="resultId">
        <el-input
          v-model="queryParams.resultId"
          placeholder="请输入事件ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别分值" prop="genderScore">
        <el-input
          v-model="queryParams.genderScore"
          placeholder="请输入性别分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年龄分值" prop="ageScore">
        <el-input
          v-model="queryParams.ageScore"
          placeholder="请输入年龄分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上衣颜色" prop="upperColor">
        <el-input
          v-model="queryParams.upperColor"
          placeholder="请输入上衣颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上衣颜色分值" prop="upperColorScore">
        <el-input
          v-model="queryParams.upperColorScore"
          placeholder="请输入上衣颜色分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下衣颜色" prop="bottomColor">
        <el-input
          v-model="queryParams.bottomColor"
          placeholder="请输入下衣颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下衣颜色分值" prop="bottomColorScore">
        <el-input
          v-model="queryParams.bottomColorScore"
          placeholder="请输入下衣颜色分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上衣类型分值" prop="upperTypeScore">
        <el-input
          v-model="queryParams.upperTypeScore"
          placeholder="请输入上衣类型分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下衣类型分值" prop="bottomTypeScore">
        <el-input
          v-model="queryParams.bottomTypeScore"
          placeholder="请输入下衣类型分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="头发" prop="hair">
        <el-input
          v-model="queryParams.hair"
          placeholder="请输入头发"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="头发分值" prop="hairScore">
        <el-input
          v-model="queryParams.hairScore"
          placeholder="请输入头发分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="帽子" prop="hat">
        <el-input
          v-model="queryParams.hat"
          placeholder="请输入帽子"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="帽子分值" prop="hatScore">
        <el-input
          v-model="queryParams.hatScore"
          placeholder="请输入帽子分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="口罩" prop="mask">
        <el-input
          v-model="queryParams.mask"
          placeholder="请输入口罩"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="口罩分值" prop="maskScore">
        <el-input
          v-model="queryParams.maskScore"
          placeholder="请输入口罩分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="眼镜" prop="glass">
        <el-input
          v-model="queryParams.glass"
          placeholder="请输入眼镜"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="眼镜分值" prop="glassScore">
        <el-input
          v-model="queryParams.glassScore"
          placeholder="请输入眼镜分值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:personAttr:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:personAttr:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:personAttr:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:personAttr:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="personAttrList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" v-if="true"/>
      <el-table-column label="事件ID" align="center" prop="resultId" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="性别分值" align="center" prop="genderScore" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="年龄分值" align="center" prop="ageScore" />
      <el-table-column label="上衣颜色" align="center" prop="upperColor" />
      <el-table-column label="上衣颜色分值" align="center" prop="upperColorScore" />
      <el-table-column label="下衣颜色" align="center" prop="bottomColor" />
      <el-table-column label="下衣颜色分值" align="center" prop="bottomColorScore" />
      <el-table-column label="上衣类型" align="center" prop="upperType" />
      <el-table-column label="上衣类型分值" align="center" prop="upperTypeScore" />
      <el-table-column label="下衣类型" align="center" prop="bottomType" />
      <el-table-column label="下衣类型分值" align="center" prop="bottomTypeScore" />
      <el-table-column label="头发" align="center" prop="hair" />
      <el-table-column label="头发分值" align="center" prop="hairScore" />
      <el-table-column label="帽子" align="center" prop="hat" />
      <el-table-column label="帽子分值" align="center" prop="hatScore" />
      <el-table-column label="口罩" align="center" prop="mask" />
      <el-table-column label="口罩分值" align="center" prop="maskScore" />
      <el-table-column label="眼镜" align="center" prop="glass" />
      <el-table-column label="眼镜分值" align="center" prop="glassScore" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:personAttr:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:personAttr:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改行人属性对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="事件ID" prop="resultId">
          <el-input v-model="form.resultId" placeholder="请输入事件ID" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="性别分值" prop="genderScore">
          <el-input v-model="form.genderScore" placeholder="请输入性别分值" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="年龄分值" prop="ageScore">
          <el-input v-model="form.ageScore" placeholder="请输入年龄分值" />
        </el-form-item>
        <el-form-item label="上衣颜色" prop="upperColor">
          <el-input v-model="form.upperColor" placeholder="请输入上衣颜色" />
        </el-form-item>
        <el-form-item label="上衣颜色分值" prop="upperColorScore">
          <el-input v-model="form.upperColorScore" placeholder="请输入上衣颜色分值" />
        </el-form-item>
        <el-form-item label="下衣颜色" prop="bottomColor">
          <el-input v-model="form.bottomColor" placeholder="请输入下衣颜色" />
        </el-form-item>
        <el-form-item label="下衣颜色分值" prop="bottomColorScore">
          <el-input v-model="form.bottomColorScore" placeholder="请输入下衣颜色分值" />
        </el-form-item>
        <el-form-item label="上衣类型分值" prop="upperTypeScore">
          <el-input v-model="form.upperTypeScore" placeholder="请输入上衣类型分值" />
        </el-form-item>
        <el-form-item label="下衣类型分值" prop="bottomTypeScore">
          <el-input v-model="form.bottomTypeScore" placeholder="请输入下衣类型分值" />
        </el-form-item>
        <el-form-item label="头发" prop="hair">
          <el-input v-model="form.hair" placeholder="请输入头发" />
        </el-form-item>
        <el-form-item label="头发分值" prop="hairScore">
          <el-input v-model="form.hairScore" placeholder="请输入头发分值" />
        </el-form-item>
        <el-form-item label="帽子" prop="hat">
          <el-input v-model="form.hat" placeholder="请输入帽子" />
        </el-form-item>
        <el-form-item label="帽子分值" prop="hatScore">
          <el-input v-model="form.hatScore" placeholder="请输入帽子分值" />
        </el-form-item>
        <el-form-item label="口罩" prop="mask">
          <el-input v-model="form.mask" placeholder="请输入口罩" />
        </el-form-item>
        <el-form-item label="口罩分值" prop="maskScore">
          <el-input v-model="form.maskScore" placeholder="请输入口罩分值" />
        </el-form-item>
        <el-form-item label="眼镜" prop="glass">
          <el-input v-model="form.glass" placeholder="请输入眼镜" />
        </el-form-item>
        <el-form-item label="眼镜分值" prop="glassScore">
          <el-input v-model="form.glassScore" placeholder="请输入眼镜分值" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPersonAttr, getPersonAttr, delPersonAttr, addPersonAttr, updatePersonAttr } from "@/api/system/personAttr";

export default {
  name: "PersonAttr",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 行人属性表格数据
      personAttrList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        resultId: undefined,
        gender: undefined,
        genderScore: undefined,
        age: undefined,
        ageScore: undefined,
        upperColor: undefined,
        upperColorScore: undefined,
        bottomColor: undefined,
        bottomColorScore: undefined,
        upperType: undefined,
        upperTypeScore: undefined,
        bottomType: undefined,
        bottomTypeScore: undefined,
        hair: undefined,
        hairScore: undefined,
        hat: undefined,
        hatScore: undefined,
        mask: undefined,
        maskScore: undefined,
        glass: undefined,
        glassScore: undefined,
        deptId: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "ID不能为空", trigger: "blur" }
        ],
        resultId: [
          { required: true, message: "事件ID不能为空", trigger: "blur" }
        ],
        gender: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        genderScore: [
          { required: true, message: "性别分值不能为空", trigger: "blur" }
        ],
        age: [
          { required: true, message: "年龄不能为空", trigger: "blur" }
        ],
        ageScore: [
          { required: true, message: "年龄分值不能为空", trigger: "blur" }
        ],
        upperColor: [
          { required: true, message: "上衣颜色不能为空", trigger: "blur" }
        ],
        upperColorScore: [
          { required: true, message: "上衣颜色分值不能为空", trigger: "blur" }
        ],
        bottomColor: [
          { required: true, message: "下衣颜色不能为空", trigger: "blur" }
        ],
        bottomColorScore: [
          { required: true, message: "下衣颜色分值不能为空", trigger: "blur" }
        ],
        upperType: [
          { required: true, message: "上衣类型不能为空", trigger: "change" }
        ],
        upperTypeScore: [
          { required: true, message: "上衣类型分值不能为空", trigger: "blur" }
        ],
        bottomType: [
          { required: true, message: "下衣类型不能为空", trigger: "change" }
        ],
        bottomTypeScore: [
          { required: true, message: "下衣类型分值不能为空", trigger: "blur" }
        ],
        hair: [
          { required: true, message: "头发不能为空", trigger: "blur" }
        ],
        hairScore: [
          { required: true, message: "头发分值不能为空", trigger: "blur" }
        ],
        hat: [
          { required: true, message: "帽子不能为空", trigger: "blur" }
        ],
        hatScore: [
          { required: true, message: "帽子分值不能为空", trigger: "blur" }
        ],
        mask: [
          { required: true, message: "口罩不能为空", trigger: "blur" }
        ],
        maskScore: [
          { required: true, message: "口罩分值不能为空", trigger: "blur" }
        ],
        glass: [
          { required: true, message: "眼镜不能为空", trigger: "blur" }
        ],
        glassScore: [
          { required: true, message: "眼镜分值不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "部门ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询行人属性列表 */
    getList() {
      this.loading = true;
      listPersonAttr(this.queryParams).then(response => {
        this.personAttrList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        resultId: undefined,
        gender: undefined,
        genderScore: undefined,
        age: undefined,
        ageScore: undefined,
        upperColor: undefined,
        upperColorScore: undefined,
        bottomColor: undefined,
        bottomColorScore: undefined,
        upperType: undefined,
        upperTypeScore: undefined,
        bottomType: undefined,
        bottomTypeScore: undefined,
        hair: undefined,
        hairScore: undefined,
        hat: undefined,
        hatScore: undefined,
        mask: undefined,
        maskScore: undefined,
        glass: undefined,
        glassScore: undefined,
        deptId: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加行人属性";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getPersonAttr(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改行人属性";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updatePersonAttr(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addPersonAttr(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除行人属性编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delPersonAttr(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/personAttr/export', {
        ...this.queryParams
      }, `personAttr_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
